import TestConfig from "../../Static/TestConfig";

cc.Class({
    extends: cc.Component,

    properties: {
        btn2:{
            default:null,
            type:cc.Node
        },

        btn6:{
            default:null,
            type:cc.Node
        },

        IconTwo:{
            default:null,
            type:cc.Sprite
        },

        IconSix:{
            default:null,
            type:cc.Sprite
        },

        botCash1:{
            default:null,
            type:cc.SpriteFrame
        },

        botCash2:{
            default:null,
            type:cc.SpriteFrame
        },

        botPractice1:{
            default:null,
            type:cc.SpriteFrame
        },

        botPractice2:{
            default:null,
            type:cc.SpriteFrame
        },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        //for test secret
        this.secretArray = []
        this.targetArray = [1,2,1,1,2]
    },

    start () {
        this.lightButtonNode(this.btn2,true)
        this.lightButtonNode(this.btn6,false)
        cc.find("Canvas").emit("lobby_player_count_select_clicked", 2)
        this.IconTwo.spriteFrame = this.botCash2;
        this.IconSix.spriteFrame = this.botPractice1;
    },

    // update (dt) {},

    onCountButtonClicked:function (event) {
        let btnName = event.target.name
        cc.find("Canvas/SoundManager").getComponent("SoundManager").playKaPaiSound()
        if(btnName === "button_2"){
            let kv = {
                keys:["ClickGamePeople"],
                values:["2"]
            }
            let jsonStr = JSON.stringify(kv)
            cc.gg.tdUtil.doSendTdEvent("click_game_people","",jsonStr)

            this.startTestClick(1)
            this.lightButtonNode(this.btn2,true)
            this.lightButtonNode(this.btn6,false)
            cc.find("Canvas").emit("lobby_player_count_select_clicked", 2)
            this.IconTwo.spriteFrame = this.botCash2;
            this.IconSix.spriteFrame = this.botPractice1;
            // this.IconTwo.node.getChildByName("label").color = cc.Color.WHITE;
            // this.IconSix.node.getChildByName("label").color = cc.Color.GRAY;
        }else if(btnName === "button_6"){
            let kv = {
                keys:["ClickGamePeople"],
                values:["6"]
            }
            let jsonStr = JSON.stringify(kv)
            cc.gg.tdUtil.doSendTdEvent("click_game_people","",jsonStr)
            this.startTestClick(2)
            this.lightButtonNode(this.btn6,true)
            this.lightButtonNode(this.btn2,false)
            cc.find("Canvas").emit("lobby_player_count_select_clicked", 6)
            this.IconTwo.spriteFrame = this.botCash1;
            this.IconSix.spriteFrame = this.botPractice2;
            // this.IconTwo.node.getChildByName("label").color = cc.Color.GRAY;
            // this.IconSix.node.getChildByName("label").color = cc.Color.WHITE;
        }
    },

    lightButtonNode:function (node,isLight) {
        cc.find("border",node).active = isLight
    },

    startTestClick:function (secret) {
        if(this.secretClickTimer){
            this.unschedule(this.secretClickTimer)
            this.secretClickTimer = null
        }

        let cb = function () {
            this.secretArray = []
            cc.log("清空连续点击")
        }

        this.secretArray.push(secret)
        if(this.checkSecretClick()){
            cc.find("Canvas/UIManager").emit("ui_show_test_content",true)
            this.secretArray = []
            cc.log("密码输入成功！")
        }else {
            this.secretClickTimer = cb.bind(this)
            this.scheduleOnce(this.secretClickTimer, 1)
        }
    },

    checkSecretClick:function () {
        for(let i=0;i<this.targetArray.length;i++){
            let nowSec = this.secretArray[i]
            if(nowSec !== this.targetArray[i])
                return false
        }
        return true
    },

    onTestButtonClicked:function (event) {
        let btnName = event.target.name
        if(btnName === "btn_open_vertical_scene"){
            // cc.gg.baseUtil.setLandscape(2)
            // cc.director.loadScene('KYC')
            cc.loader.loadRes("windows/KYC", cc.Prefab, function (err, prefab) {
                let newNode = cc.instantiate(prefab)
                cc.find("Canvas/Windows").addChild(newNode)
                cc.loader.releaseRes("windows/KYC")
            }.bind(this))
        }else if(btnName === "btn_close"){
            cc.find("Canvas/UIManager").emit("ui_show_test_content",false)
        }else if(btnName === "btn_open_test_scene1"){
            cc.director.loadScene("Test")
        }else if(btnName === "btn4"){
            cc.gg.gameDataUtil.guestCanOpenEverything = true
        }else if(btnName === "btn5"){
            cc.gg.baseUtil.openWhatsApp("https://chat.whatsapp.com/Lb6h12aWzH4KoHqgXQn5la")
        }else if(btnName === "btn6"){
            cc.director.loadScene("WebScene",function () {
                cc.find("Canvas").getComponent("WebScene").webNode.getComponent(cc.WebView).url = "https://rozrummy.com/payment_test_2.html"
            })
        }else if(btnName === "btn7"){
            cc.gg.baseUtil.loginWithGoogle()
        }else if(btnName === "btn8"){
            TestConfig.ignoreMobile = true
        }else if(btnName === "btn9"){
            cc.director.loadScene('TestDisDeck')
        }else if(btnName === "btn10"){
            let channel = cc.gg.gameDataUtil.getPakageChannel()
            cc.gg.toastMgr.showDialogOneButton("channel","OK","This apk's channel is "+channel,function () {
                cc.gg.toastMgr.removeDialog()
            })
        }else if(btnName === "btn11"){
            // cc.gg.baseUtil.openGalary(cc.gg.httpUtil.rootUrl+"/user/doc/kyc/pan/img/upload",2)
            cc.game.uploadFileFinish(2)
        }else if(btnName === "btn12"){
            cc.gg.baseUtil.loginWithFaceBook()
        }else if(btnName === "btn13"){
            cc.gg.toastMgr.showDialogOneButton("channel","OK","This apk's rooturl is "+cc.gg.httpUtil.rootUrl,function () {
                cc.gg.toastMgr.removeDialog()
            })
        }else if(btnName === "btn14"){
            cc.gg.baseUtil._onBackPressed()
        }else if(btnName === "btn15"){
            cc.gg.gameDataUtil.guestCanCollect = true
        }else if(btnName === "btn16"){
            cc.gg.gameDataUtil.openKYCWithoutMoney = true
        }else if(btnName === "btn17") {
            cc.gg.logicUtil.onKickSinceCoinNotEnough()
        }
    },
});
